from pydantic import BaseModel,Field, field_validator,validator
import re


class UserData(BaseModel):
    account: str = Field(min_length=5,max_length=12,title="账号", default="admin")
    password: str = '123456'

    # 密码复杂度验证
    @field_validator("password")
    @classmethod
    def validator_password(cls, value):
        # if re.match(r'^.*(?=.{6,})(?=.*\d)(?=.*[a-z]|[A-Z]{1,}).*$', value): # 真正需要再用
        if len(value) >= 6:
            return value
        else:
            raise ValueError('请输入至少包一位字母和数字的密码')
            # return respone.success(code=-1, msg="请输入至少包一位字母和数字")
